package com.match.competition_role.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.match.competition_role.entity.CompetitionRole;
import com.match.competition_role.entity.CompetitionUserRole;
import com.match.competition_role.mapper.CompetitionRoleMapper;
import com.match.competition_role.service.CompetitionRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.match.competition_role.service.CompetitionUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AdiosF
 * @since 2021-10-02
 */
@Service
public class CompetitionRoleServiceImpl extends ServiceImpl<CompetitionRoleMapper, CompetitionRole> implements CompetitionRoleService {
    @Autowired
    private CompetitionUserRoleService competitionUserRoleService;

    /**
     * 根据用户职工号获取用户角色
     * @param number
     * @return
     */
    @Override
    public List<CompetitionRole> getUserRoleByNumber(String number) {
        List<CompetitionUserRole> userRoleList = competitionUserRoleService.list(new QueryWrapper<CompetitionUserRole>().eq("user_id", number).select("role_id"));
        List<String> stringList=userRoleList.stream().map(item -> item.getRoleId()).collect(Collectors.toList());
        List<CompetitionRole> competitionRoles=new ArrayList<>();
        if (stringList.size()>0){
           competitionRoles=baseMapper.selectBatchIds(stringList);
        }
        return competitionRoles;
    }
}
